package com.yjy;

import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class MainTest {
    public static void main(String[] args) {
        Field nameField = ReflectionUtils.findField(Person.class, "name");
        Person person = new Person() {{
            setName("name1");
        }};
        ReflectionUtils.makeAccessible(nameField);
        Object name = ReflectionUtils.getField(nameField, person);
        System.out.println(name);

        ReflectionUtils.setField(nameField, person, "name22");
        System.out.println(person.getName());

        Method[] methods = ReflectionUtils.getAllDeclaredMethods(Person.class);
        for (Method method : methods) {
            System.out.println(method.getName());
        }
    }
}

class Father {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

class Person extends Father {
    private Integer age;
    public Integer getAge() {
        return age;
    }
    public void setAge(Integer age) {
        this.age = age;
    }
}
